function UserBcjkh() {
    this.form = this.InitForm();

    var year = $("#hidyear").val();
    var quarter = $("#hidquarter").val();
    $("#year").val(year);
    $("#quarter").val(quarter);

    var month = 3;//根据季度来设置月份
    if (quarter == 2) month = 6;
    if (quarter == 3) month = 9;
    if (quarter == 4) month = 12;
    $("#hidmonth").val(month);

    this.form.render('select');
    $("#bottom_btns").hide();

    this.orgsuytable = this.InitOrgSuyTable();
    this.tab = this.InitTab();
    this.table = null;
}

UserBcjkh.prototype.InitForm = function () {
    var form;
    layui.use('form', function () {
        form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        // 选择框事件，去掉
        form.on('select(year)', function (data) {
            $("#hidyear").val(data.value);
            form.render('select');
            vDSOPayDept.searchtableorgsuy();
        });
        form.on('select(quarter)', function (data) {
            $("#hidquarter").val(data.value);
            form.render('select');
            vDSOPayDept.searchtableorgsuy();
        });

        form.render();
    });
    return form;
}

//tab切换
UserBcjkh.prototype.InitTab = function () {
    var element;
    layui.use('element', function () {
        element = layui.element;

        element.on('tab(tabcontent)', function (data) {
            if (data.index == 1) {
                $("#bottom_btns").show();
                if ($("#hidstatus").val() != '') {
                    var status = Number($("#hidstatus").val());
                    if (status > 0 && status != 4 && status != 5) {
                        $("#btnbmtj").attr("disabled", "disabled");
                        $("#btnbmxg").hide();
                        $("#btnbmtj").html("该部门已确认");
                    }
                }
            } else {
                $("#hidorgid").val(0);
                $("#hidorgsummaryid").val(0);
                $("#hidstatus").val('');
                $("#bottom_btns").hide();
                $("#btnbmtj").removeAttr("disabled");
                $("#btnbmxg").show();
                $("#realname").val("");
            }
        });

    });
    return element;
}

function getstatu(statu) {
    var text = statu;
    var ret = "";
    if (text == "0") {
        ret = '保存';
    }
    else if (text == "1") {
        ret = '发布';
    }
    else if (text == "2") {
        ret = '确认';
    }
    else if (text == "3") {
        ret = '归档';
    }
    else if (text == "4" || text == "5") {
        ret = '驳回';
    }
    return ret;
}

//组织机构树初始化
UserBcjkh.prototype.InitOrgSuyTable = function () {
    var table;
    var _this = this;
    layui.use('table', function () {
        table = layui.table;
        table.render({
            elem: '#orgsuylist'
            , height: $(window).height() - 140
            , url: 'get_org_deptwork_dept_list' // 数据接口
            , page: true // 开启分页
            , limit: 30
            , id: 'orgsuylist'
            , method: "post"
            , cols: [[
                {type: 'numbers'}
                , {field: 'orgname', title: '单位名称', width: 250, align: 'center'}
                , {field: 'year', title: '年', width: 100, align: 'center'}
                , {field: 'quarter', title: '季度', width: 100, align: 'center'}
                , {field: 'status', title: '状态', width: 120, align: 'center'}
                , {title: '操作', width: 100, align: 'left', toolbar: '#operateorgsuy'}
            ]]
            , request: {
                type: 'post'
            }
            , page: false
            , where: {
                year: $("#hidyear").val(),
                month: $("#hidmonth").val()
            }
            , even: true //开启隔行背景
            , done: function (res, page, count) {
                var dataarr = res.data;
                $("[data-field='status']").children().each(function (index) {
                    if (index > 0) {

                        var  thisdata=dataarr[index-1];
                        var text = $(this).text();
                          if(!thisdata.usercount||thisdata.usercount<=1){
                              text='9';
                          }
                        switch (text) {
                            case null:
                                $(this).text("未填报");
                                break;
                            case '':
                                $(this).text("未填报");
                                break;
                            case '0':
                                $(this).text("填报");
                                break;
                            case '1':
                                $(this).text("确认");
                                break;
                            case '2':
                                $(this).text("审核通过");
                                break;
                            case '3':
                                $(this).text("归档");
                                break;
                            case '4':
                                $(this).text("驳回");
                                break;
                            case '5':
                                $(this).text("驳回");
                                break;
                            case '9':
                                $(this).text("");
                                break;
                        }
                    }
                })
                $("[data-field='quarter']").children().each(function (index) {
                    if (index > 0) {
                        var text = $(this).text();
                        switch (text) {
                            case null:
                            case '':
                                var month = dataarr[index - 1].month;
                                if (month == 1 || month == 2 || month == 3) {
                                    $(this).text("第一季度");
                                }
                                if (month == 4 || month == 5 || month == 6) {
                                    $(this).text("第二季度");
                                }
                                if (month == 7 || month == 8 || month == 9) {
                                    $(this).text("第三季度");
                                }
                                if (month == 10 || month == 11 || month == 12) {
                                    $(this).text("第四季度");
                                }
                                break;
                            case '1':
                                $(this).text("第一季度");
                                break;
                            case '2':
                                $(this).text("第二季度");
                                break;
                            case '3':
                                $(this).text("第三季度");
                                break;
                            case '4':
                                $(this).text("第四季度");
                                break;
                        }
                    }
                })
            }
        });


        //监听工具条
        table.on('tool(orgsuylist)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                $("#hidorgid").val(data.orgid);
                $("#hidorgsummaryid").val(data.orgsummaryid);
                $("#hidstatus").val(data.status);
                $("#hidmonth").val(data.month);

                console.log('detail');
                var quarter = 1;
                if (data.month == 4 || data.month == 5 || data.month == 6) quarter = 2;
                if (data.month == 7 || data.month == 8 || data.month == 9) quarter = 3;
                if (data.month == 10 || data.month == 11 || data.month == 12) quarter = 4;
                $("#hidquarter").val(quarter);
                _this.OpTab(2, data);
                $("#table_title").html("房山公安分局"+data.orgname + " " + data.year + " 年第" + quarter + " 季季度津贴");

                _this.table = _this.InitTableByBt(data.orgid, data.orgsummaryid);
            } else if (obj.event === 'tijiao') {
                vDSOPayDept.btntijiao(data.orgsummaryid, 1);
            } else if (obj.event === 'shengcheng') {
                vDSOPayDept.createatttb(data.orgid,data.year, $("#hidmonth").val());
            }

        });
    });

    return table;
}

UserBcjkh.prototype.OpTab = function (tabindex, obj) {
    this.tab.tabChange('tabcontent', tabindex);
}

//生成季度数据
UserBcjkh.prototype.createatttb = function (orgid, year, month) {
    var orgids = orgid;

    top.ShowZheZhao();
    $.ajax({
        type: "POST",
        url: "create_depsub_pay",
        data: {orgid: orgids, year: year, month: month},
        beforeSend: function (XHR) {

        },
        success: function (data) {
            data = eval('(' + data + ')');
            if (data.result > 0) {
                top.mylayui.msg(data.msg, {icon: 1});
                vDSOPayDept.searchtableorgsuy();
            }
            else {
                top.mylayui.msg(data.msg, {icon: 0});
            }
            top.ShowZheZhao();
        },
        complete: function (XHR) {
            top.mylayui.closeAll('loading');
        },
        error: function () {

        }
    });
}

//表详细初始化
UserBcjkh.prototype.InitTableByBt = function (orgid, orgsummaryid) {
    console.log('init');
    var table;
    var _this = this;
    layui.use('table', function () {
        var quarter = $('#quarter').val();
        var month1 = "一月";
        var month2 = "二月";
        var month3 = "三月";
        if (quarter == 2) {
            month1 = "四月";
            month2 = "五月";
            month3 = "六月"
        }
        if (quarter == 3) {
            month1 = "七月";
            month2 = "八月";
            month3 = "九月"
        }
        if (quarter == 4) {
            month1 = "十月";
            month2 = "十一月";
            month3 = "十二月"
        }

        table = layui.table;
        table.render({
            elem: '#list'
            , height: $(window).height() - 300
            , url: 'get_deptsw_dept_list' // 数据接口
            , page: true // 开启分页
            , limit: 40
            , id: 'vtdpuserlist'
            , limits: [20, 40, 80, 100]
            , method: "post"
            , cols: [[ // 表头
                {field: 'realname', title: '姓名', width: 120, align: 'center', rowspan: 3, fixed: 'left'}
                , {field: 'orgname', title: '部门', width: 120, align: 'center', rowspan: 3}
                , {field: 'cardno', title: '身份证号', width: 180, align: 'center', rowspan: 3}
                , {field: 'status', title: '状态', width: 100, align: 'center', rowspan: 3}
                , {field: 'summoney', title: '合计', width: 180, align: 'center', rowspan: 3}
                , {title: '执勤岗位津贴', align: 'center', colspan: 13}
                , {title: '季度保留津贴', align: 'center', colspan: 4}
                , {title: '加班补贴', align: 'center', colspan: 4}
                , {title: '本人签字', width: 100, align: 'center', rowspan: 3}
                , {field: 'remark', title: '备注', width: 180, align: 'center', rowspan: 3, edit: 'text'}
            ],
                [
                    {field: 'dutynumsum', title: '值勤岗位津贴合计', width: 180, align: 'center', rowspan: 2}
                    , {title: '一类岗执行50元标准', width: 100, align: 'center', colspan: 6}
                    , {title: '二类岗执行40元标准', width: 100, align: 'center', colspan: 6}
                    , {field: 'retainnumsum', title: '保留津贴合计', width: 180, align: 'center', rowspan: 2}
                    , {
                    field: 'retainnum1',
                    title: '' + month1 + '',
                    width: 180,
                    align: 'center',
                    rowspan: 2,
                    edit: 'text'
                }
                    , {
                    field: 'retainnum2',
                    title: '' + month2 + '',
                    width: 180,
                    align: 'center',
                    rowspan: 2,
                    edit: 'text'
                }
                    , {
                    field: 'retainnum3',
                    title: '' + month3 + '',
                    width: 180,
                    align: 'center',
                    rowspan: 2,
                    edit: 'text'
                }
                    , {field: 'overtimenumsum', title: '加班补贴合计', width: 180, align: 'center', rowspan: 2}
                    , {
                    field: 'overtimenum1',
                    title: '' + month1 + '',
                    width: 180,
                    align: 'center',
                    rowspan: 2,
                    edit: 'text'
                }
                    , {
                    field: 'overtimenum2',
                    title: '' + month2 + '',
                    width: 180,
                    align: 'center',
                    rowspan: 2,
                    edit: 'text'
                }
                    , {
                    field: 'overtimenum3',
                    title: '' + month3 + '',
                    width: 180,
                    align: 'center',
                    rowspan: 2,
                    edit: 'text'
                }
                ],
                [
                    {field: 'dutynumday1', title: month1+'（每月最高30天）', width: 180, edit: 'text',align: 'center'}
                    , {field: 'dutynum1', title: '金额', width: 80, align: 'center'}
                    , {field: 'dutynumday12', title: month2+'（每月最高30天）', width: 180,edit: 'text' ,align: 'center'}
                    , {field: 'dutynum12', title: '金额', width: 80, align: 'center'}
                    , {field: 'dutynumday13', title: month3+'（每月最高30天）', width: 180,edit: 'text', align: 'center'}
                    , {field: 'dutynum13', title: '金额', width: 80, align: 'center'}
                    , {field: 'dutynumday2', title: month1+'（每月最高26天）', width: 180,edit: 'text', align: 'center'}
                    , {field: 'dutynum2', title: '金额', width: 80, align: 'center'}
                    , {field: 'dutynumday22', title: month2+'（每月最高26天）', width: 180,edit: 'text', align: 'center'}
                    , {field: 'dutynum22', title: '金额', width: 80, align: 'center'}
                    , {field: 'dutynumday23', title: month3+'（每月最高26天）', width: 180, edit: 'text',align: 'center'}
                    , {field: 'dutynum23', title: '金额', width: 80, align: 'center'}
                ]
            ]
            , request: {
                type: 'post'
            }
            , where: {
                year: $("#year").val(),
                quarter: $("#quarter").val(),
                orgid: orgid,
                realname:$("#realname").val(),
                status: $("#hidstatus").val()
            }
            , done: function (res, page, count) {
                var message = res.msg;
                $("#table_info").val(message);
                var status = Number($("#hidstatus").val());
                $("[data-field='status']").children().each(function (index) {
                    var text = $(this).text();
                    if (text == "0") {
                        $(this).text('保存')
                    }
                    else if (text == "1") {
                        $(this).text('确认')
                    }
                    else if (text == "2") {
                        $(this).text('确认')
                    }
                    else if (text == "3") {
                        $(this).text('归档')
                    }
                    else if (text == "4"||text=="5") {
                        $(this).text('驳回')
                    }
                })

                console.log(status);
                if(status == null || status == 0 || status == 4 ||status ==5) {
                    $("[data-field='dutynumday1']").children().each(function (index) {
                        $($(this)[0]).addClass('cellColor');
                    })

                    $("[data-field='dutynumday2']").children().each(function (index) {
                        $($(this)[0]).addClass('cellColor');
                    })

                    $("[data-field='dutynumday12']").children().each(function (index) {
                        $($(this)[0]).addClass('cellColor');
                    })

                    $("[data-field='dutynumday22']").children().each(function (index) {
                        $($(this)[0]).addClass('cellColor');
                    })

                    $("[data-field='dutynumday13']").children().each(function (index) {
                        $($(this)[0]).addClass('cellColor');
                    })

                    $("[data-field='dutynumday23']").children().each(function (index) {
                        $($(this)[0]).addClass('cellColor');
                    })

                    $("[data-field='retainnum1']").children().each(function (index) {
                        $($(this)[0]).addClass('cellColor');
                    })

                    $("[data-field='retainnum2']").children().each(function (index) {
                        $($(this)[0]).addClass('cellColor');
                    })
                    $("[data-field='retainnum3']").children().each(function (index) {
                        $($(this)[0]).addClass('cellColor');
                    })

                    $("[data-field='overtimenum1']").children().each(function (index) {
                        $($(this)[0]).addClass('cellColor');
                    })
                    $("[data-field='overtimenum2']").children().each(function (index) {
                        $($(this)[0]).addClass('cellColor');
                    })

                    $("[data-field='overtimenum3']").children().each(function (index) {
                        $($(this)[0]).addClass('cellColor');
                    })
                    $("[data-field='remark']").children().each(function (index) {
                        $($(this)[0]).addClass('cellColor');
                    })
                }
            }
        });
        table.on('edit(list)', function (obj) {
            var data = obj.data;
            var day = obj.value; //得到修改后的值
            var field = obj.field;

            if (field == 'dutynumday1') {
                //动态获取表序列
                var indexTable = 0;
                if( $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[6]).init().length == 0) indexTable = 1;
                if (parseFloat(day).toString() == "NaN") {
                    $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[6]).text(0);
                    data.dutynumday1=0;
                    day = 0;
                    top.mylayui.msg("请输入数字", {icon: 0})
                }
                if (day > 30) {
                    $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[6]).text(30);
                    data.dutynumday1=30;
                    day = 30;
                }
                data.dutynum1 = day * 50;
                $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[7]).text(day * 50)

            }
            if (field == 'dutynumday12') {
                //动态获取表序列
                var indexTable = 0;
                if( $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[8]).init().length == 0) indexTable = 1;
                if (parseFloat(day).toString() == "NaN") {
                    $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[8]).text(0);
                    data.dutynumday12=0;
                    day = 0;
                    top.mylayui.msg("请输入数字", {icon: 0})
                }
                if (day > 30) {
                    $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[8]).text(30);
                    data.dutynumday12=30;
                    day = 30;
                }
                data.dutynum12 = day * 50;
                $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[9]).text(day * 50)

            }
            if (field == 'dutynumday13') {
                //动态获取表序列
                var indexTable = 0;
                if( $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[10]).init().length == 0) indexTable = 1;
                if (parseFloat(day).toString() == "NaN") {
                    $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[10]).text(0);
                    data.dutynumday13=0;
                    day = 0;
                    top.mylayui.msg("请输入数字", {icon: 0})
                }
                if (day > 30) {
                    $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[10]).text(30);
                    data.dutynumday13=30;
                    day = 30;
                }
                data.dutynum13 = day * 50;
                $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[11]).text(day * 50)

            }
            if (field == 'dutynumday2') {
                //动态获取表的序列
                var indexTable = 0;
                if( $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[12]).init().length  == 0) indexTable = 1;
                if (parseFloat(day).toString() == "NaN") {
                    $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[12]).text(0);
                    data.dutynumday2 =0;
                    day = 0;
                    top.mylayui.msg("请输入数字", {icon: 0})
                }

                if (day > 26) {
                    $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[12]).text(26)
                    day = 26;
                    data.dutynumday2=26;
                }
                data.dutynum2 = day * 40;
                $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[13]).text(day * 40)
            }
            if (field == 'dutynumday22') {
                //动态获取表的序列
                var indexTable = 0;
                if( $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[14]).init().length  == 0) indexTable = 1;
                if (parseFloat(day).toString() == "NaN") {
                    $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[14]).text(0);
                    data.dutynumday22 =0;
                    day = 0;
                    top.mylayui.msg("请输入数字", {icon: 0})
                }

                if (day > 26) {
                    $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[14]).text(26)
                    day = 26;
                    data.dutynumday22=26;
                }
                data.dutynum22 = day * 40;
                $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[15]).text(day * 40)
            }
            if (field == 'dutynumday23') {
                //动态获取表的序列
                var indexTable = 0;
                if( $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[16]).init().length  == 0) indexTable = 1;
                if (parseFloat(day).toString() == "NaN") {
                    $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[16]).text(0);
                    data.dutynumday23 =0;
                    day = 0;
                    top.mylayui.msg("请输入数字", {icon: 0})
                }

                if (day > 26) {
                    $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[16]).text(26)
                    day = 26;
                    data.dutynumday23=26;
                }
                data.dutynum23 = day * 40;
                $($(".layui-table-box tr[data-index=" + data.LAY_TABLE_INDEX + "]")[indexTable].children[17]).text(day * 40)
            }
            if (field == 'retainnum1' || field == 'retainnum2' || field == 'retainnum3') {
                data.retainnumsum = Number(data.retainnumsum) + Number(day);
            }
            if (field == 'overtimenum1' || field == 'overtimenum2' || field == 'overtimenum3') {
                data.overtimenumsum = Number(data.overtimenumsum) + Number(day);
            }
        });
    });
    return table;
}

//表查询
UserBcjkh.prototype.searchtable = function () {
    var quarter = $('#quarter').val();
    var month1 = "一月";
    var month2 = "二月";
    var month3 = "三月";
    if (quarter == 2) {
        month1 = "四月";
        month2 = "五月";
        month3 = "六月"
    }
    if (quarter == 3) {
        month1 = "七月";
        month2 = "八月";
        month3 = "九月"
    }
    if (quarter == 4) {
        month1 = "十月";
        month2 = "十一月";
        month3 = "十二月"
    }
    this.table.reload('vtdpuserlist', {
        cols: [[ // 表头
            {
                field: 'realname',
                title: '姓名',
                width: 120,
                align: 'center',
                rowspan: 3,
                fixed: 'left',
                templet: '#realnameTpl'
            }
            , {field: 'orgname', title: '部门', width: 120, align: 'center', rowspan: 3}
            , {field: 'cardno', title: '身份证号', width: 180, align: 'center', rowspan: 3}
            , {field: 'status', title: '状态', width: 100, align: 'center', rowspan: 3}
            , {field: 'summoney', title: '合计', width: 180, align: 'center', rowspan: 3}
            , {title: '执勤岗位津贴', align: 'center', colspan: 13}
            , {title: '季度保留津贴', align: 'center', colspan: 4}
            , {title: '加班补贴', align: 'center', colspan: 4}
            , {title: '本人签字', width: 100, align: 'center', rowspan: 3}
            , {field: 'remark', title: '备注', width: 180, align: 'center', rowspan: 3, edit: 'text'}
        ],
            [
                {field: 'dutynumsum', title: '值勤岗位津贴合计', width: 180, align: 'center', rowspan: 2}
                , {title: '一类岗执行50元标准', width: 100, align: 'center', colspan: 6}
                , {title: '二类岗执行40元标准', width: 100, align: 'center', colspan: 6}
                , {field: 'retainnumsum', title: '保留津贴合计', width: 180, align: 'center', rowspan: 2}
                , {field: 'retainnum1', title: '' + month1 + '', width: 180, align: 'center', rowspan: 2, edit: 'text'}
                , {field: 'retainnum2', title: '' + month2 + '', width: 180, align: 'center', rowspan: 2, edit: 'text'}
                , {field: 'retainnum3', title: '' + month3 + '', width: 180, align: 'center', rowspan: 2, edit: 'text'}
                , {field: 'overtimenumsum', title: '加班补贴合计', width: 180, align: 'center', rowspan: 2}
                , {
                field: 'overtimenum1',
                title: '' + month1 + '',
                width: 180,
                align: 'center',
                rowspan: 2,
                edit: 'text'
            }
                , {
                field: 'overtimenum2',
                title: '' + month2 + '',
                width: 180,
                align: 'center',
                rowspan: 2,
                edit: 'text'
            }
                , {
                field: 'overtimenum3',
                title: '' + month3 + '',
                width: 180,
                align: 'center',
                rowspan: 2,
                edit: 'text'
            }
            ],
            [
                {field: 'dutynumday1', title: month1+'（每月最高30天）', width: 180, edit: 'text',align: 'center'}
                , {field: 'dutynum1', title: '金额', width: 80, align: 'center'}
                , {field: 'dutynumday12', title: month2+'（每月最高30天）', width: 180,edit: 'text' ,align: 'center'}
                , {field: 'dutynum12', title: '金额', width: 80, align: 'center'}
                , {field: 'dutynumday13', title: month3+'（每月最高30天）', width: 180,edit: 'text', align: 'center'}
                , {field: 'dutynum13', title: '金额', width: 80, align: 'center'}
                , {field: 'dutynumday2', title: month1+'（每月最高26天）', width: 180,edit: 'text', align: 'center'}
                , {field: 'dutynum2', title: '金额', width: 80, align: 'center'}
                , {field: 'dutynumday22', title: month2+'（每月最高26天）', width: 180,edit: 'text', align: 'center'}
                , {field: 'dutynum22', title: '金额', width: 80, align: 'center'}
                , {field: 'dutynumday23', title: month3+'（每月最高26天）', width: 180, edit: 'text',align: 'center'}
                , {field: 'dutynum23', title: '金额', width: 80, align: 'center'}
            ]
        ]
        , page: {
            curr: 1 //重新从第 1 页开始
        }
        , where: {
            year: $("#year").val(),
            realname:$("#realname").val(),
            quarter: $("#quarter").val(),
            orgid: $("#hidorgid").val(),
        }
    });
}

UserBcjkh.prototype.btntijiao = function (orgsummaryid, status) {
    top.mylayui.confirm('点击确认后，津贴会提交到部门领导进行审批', {icon: 0}, function (index, dd) {
        top.mylayui.close(index);
        $.ajax({
            type: "POST",
            url: "deptsw_pay_update_status",
            data: {orgsummaryid: orgsummaryid, status: status},
            beforeSend: function (XHR) {

            },
            success: function (data) {
                data = eval('(' + data + ')');
                if (data.result > 0) {
                    top.mylayui.msg(data.msg, {icon: 1});
                    //刷新
                    vDSOPayDept.searchtableorgsuy();
                }
                else {
                    top.mylayui.msg(data.msg, {icon: 0});
                }
            },
            complete: function (XHR) {

            },
            error: function () {

            }
        });
    })
}

UserBcjkh.prototype.detailbtntijiao = function () {
    var orgsummaryid=$("#hidorgsummaryid").val();
    top.mylayui.confirm('点击确认后，津贴会提交到部门领导进行审批', {icon: 0}, function (index, dd) {
        top.mylayui.close(index);
        $.ajax({
            type: "POST",
            url: "deptsw_pay_update_status",
            data: {orgsummaryid: orgsummaryid, status: 1},
            beforeSend: function (XHR) {

            },
            success: function (data) {
                data = eval('(' + data + ')');
                if (data.result > 0) {
                    top.mylayui.msg(data.msg, {icon: 1});
                    //刷新
                    vDSOPayDept.querydetail();
                }
                else {
                    top.mylayui.msg(data.msg, {icon: 0});
                }
            },
            complete: function (XHR) {

            },
            error: function () {

            }
        });
    })
}

UserBcjkh.prototype.querydetail = function () {
    if ($("#hidorgid").val() == "" || $("#hidorgid").val() == "0") {
        top.mylayui.msg('请先点机构列表后面详情按钮，再点击查询', {icon: 0});
        return;
    }

    this.InitTableByBt($("#hidorgid").val(), $("#hidorgsummaryid").val());
}

//季度津贴保存
UserBcjkh.prototype.save = function () {
    var tabledatastr = JSON.stringify(this.table.cache);
    var tabledataJson = JSON.parse(tabledatastr);
    delete tabledataJson.orgsuylist;
    var year = $("#year").val();
    var quarter = $('#quarter').val();
    tabledataJson['year'] = year;
    tabledataJson['quarter'] = quarter;
    tabledataJson = JSON.stringify(tabledataJson);
    tabledataJson = tabledataJson.replace(/LAY_TABLE_INDEX/g, 'lay_TABLE_INDEX');
    $.ajax({
        type: "POST",
        url: "deptsw_pay_save",
        contentType: 'application/json',
        data: tabledataJson,
        beforeSend: function (XHR) {

        },
        success: function (data) {
            data = eval('(' + data + ')');
            if (data.result > 0) {
                top.mylayui.msg(data.msg, {icon: 1});
                vDSOPayDept.searchtable();

            }
            else {
                top.mylayui.msg(data.msg, {icon: 0});
            }
        },
        complete: function (XHR) {

        },
        error: function () {

        }
    });
}

//季度津贴导出
UserBcjkh.prototype.export = function () {
    top.ShowZheZhao();
    var year = $("#year").val();
    var quarter = $("#quarter").val();
    var orgid = $("#hidorgid").val();
    $.ajax({
        type: "POST",
        url: "deptsw_pay_export",
        data: {year: year, quarter: quarter, orgid: orgid,owner: 0},
        beforeSend: function (XHR) {

        },
        success: function (data) {
            data = eval('(' + data + ')');
            if (data.result > 0) {
                window.open(data.msg, '_self');
            }
            else {
                top.mylayui.msg(data.msg, {icon: 0});
            }
        },
        complete: function (XHR) {
            top.ShowZheZhao();
        },
        error: function () {
        }
    });
}

UserBcjkh.prototype.updatestatus = function (orgsummaryid, status) {
    top.mylayui.confirm('点击确认后，津贴会提交到部门领导进行审批', {icon: 0}, function (index, dd) {
        top.mylayui.close(index);
        $.ajax({
            type: "POST",
            url: "deptsw_pay_update_status",
            data: {orgsummaryid: orgsummaryid, status: status},
            beforeSend: function (XHR) {

            },
            success: function (data) {
                data = eval('(' + data + ')');
                if (data.result > 0) {
                    top.mylayui.msg(data.msg, {icon: 1});
                }
                else {
                    top.mylayui.msg(data.msg, {icon: 0});
                }
            },
            complete: function (XHR) {

            },
            error: function () {

            }
        });
    })
}

UserBcjkh.prototype.searchtableorgsuy = function () {

    var month = 3;//根据季度来设置月份
    var quarter = $("#hidquarter").val();
    if (quarter == 2) month = 6;
    if (quarter == 3) month = 9;
    if (quarter == 4) month = 12;
    $("#hidmonth").val(month);
    console.log("内层处理开始！");
    this.orgsuytable.reload('orgsuylist', {
        page: {
            curr: 1 //重新从第 1 页开始
        }
        , page: false
        , where: {
            year: $("#hidyear").val(),
            month: $("#hidmonth").val()
        }
    });
}


//季度津贴确认
UserBcjkh.prototype.update = function (status) {
    var tabledataJson = this.table.cache;
    var year = $("#year").val();
    var quarter = $('input[name="quarter"]:checked ').val();
    tabledataJson['year'] = year;
    tabledataJson['quarter'] = quarter;
    tabledataJson['status'] = status;
    tabledataJson = JSON.stringify(tabledataJson);
    tabledataJson = tabledataJson.replace(/LAY_TABLE_INDEX/g, 'lay_TABLE_INDEX');

    top.mylayui.confirm('确定要提交吗？', {icon: 0}, function (index, dd) {
        top.mylayui.close(index);
        $.ajax({
            type: "POST",
            url: "deptsw_pay_update",
            contentType: 'application/json',
            data: tabledataJson,
            beforeSend: function (XHR) {

            },
            success: function (data) {
                data = eval('(' + data + ')');
                if (data.result > 0) {
                    top.mylayui.msg(data.msg, {icon: 1});
                }
                else {
                    top.mylayui.msg(data.msg, {icon: 0});
                }
            },
            complete: function (XHR) {
            },
            error: function (XHR, errorText, errorType) {
                var res = XHR.responseText;
                top.mylayui.msg('操作失败', {icon: 0});
            }
        });
    })
}

UserBcjkh.prototype.addresult = function (result, msg) {
    if (result > 0) {
        top.mylayui.msg('操作成功', {icon: 1});
        top.mylayui.closeAll('iframe');
        vDSOPayDept.searchtable();
    }
    else {
        if (msg) {
            top.mylayui.msg(msg, {icon: 0});
        } else {
            top.mylayui.msg('操作失败', {icon: 0});
        }
    }
}

var vDSOPayDept;
$(function () {
    vDSOPayDept = new UserBcjkh();
})


